package com.model.region
{
	import com.model.InteractivePage;
	import com.services.IActiveResourceConverter;

	public class RegionConverter implements IActiveResourceConverter
	{
		private var _page:InteractivePage = null;
		
		public function RegionConverter(page:InteractivePage) {
			_page = page;
		}

		public function remoteToLocal(obj:Object, localObj:Object=null):Object {
			var region:Region = _page.createRegion(obj.id);
			region.regionX = obj['x'];
			region.regionY = obj['y'];
			region.regionWidth = obj['width'];
			region.regionHeight = obj['height'];
			region.type = obj['region-type'];
			region.extraData = obj['extra-data'];
			
			return region;
		}
		
		public function localToRemote(obj:Object):Object {
			var remoteRegion:Object = new Object();
			remoteRegion["region[x]"] = obj.regionX;
			remoteRegion["region[y]"] = obj.regionY;
			remoteRegion["region[width]"] = obj.regionWidth;
			remoteRegion["region[height]"] = obj.regionHeight;
			remoteRegion["region[region_type]"] = obj.type;
			remoteRegion["region[extra_data]"] = obj.extraData;
			return remoteRegion;
		}
		
		public function isDBProperty(propertyName:String):Boolean {
			return true;
		}
		
	}
}